var createAddForm = function(selNode)
{	
	var textAreaTitle = new Ext.form.TextField({
		xtype     : 'textfield',
		id        : 'title',
		fieldLabel: 'Title',
		allowBlank: false,
		anchor    : '100%'	
	});

	var textAreaEmail = new Ext.form.TextField({
		xtype     : 'textfield',
		id        : 'email',
		fieldLabel: 'e-mail',
		allowBlank: false,
		anchor    : '100%'		
	});
	
	var textAreaAdress = new Ext.form.TextField({
		xtype     : 'textfield',
		id        : 'adress',
		fieldLabel: 'Adress',
		allowBlank: false,
		anchor    : '100%'	
	});

	var textAreaWebsite = new Ext.form.TextField({
		xtype     : 'textfield',
		id        : 'website',
		fieldLabel: 'Website',
		allowBlank: true,
		anchor    : '100%'	
	});
	
	var textAreaDescription = new Ext.form.TextField({
		xtype     : 'textfield',
		id        : 'description',
		fieldLabel: 'Description',
		allowBlank: false,
		anchor    : '100%'	
	});
	
	var textAreaCompanyName = new Ext.form.TextField({
		xtype     : 'textfield',
		id        : 'CompanyName',
		fieldLabel: 'Company name',
		allowBlank: false,
		anchor    : '100%'		
	});
	
	var textAreaCountPersons = new Ext.form.NumberField({
		xtype     : 'numberfield',
		id        : 'count_persons',
		fieldLabel: 'Number of people',
		allowBlank: false,
		anchor    : '100%'		
	});
	
	var textAreaPrice = new Ext.form.NumberField({
		xtype     : 'numberfield',
		id        : 'price',
		fieldLabel: 'Price',
		allowBlank: false,
		anchor    : '100%'		
	});
	
	var textAreaTouristName = new Ext.form.TextField({
		xtype     : 'textfield',
		id        : 'tourist_name',
		fieldLabel: 'Name tourist',
		allowBlank: false,
		anchor    : '100%'		
	});
	
	var textAreaPhoneNumber = new Ext.form.NumberField({
		xtype     : 'numberfield',
		id        : 'PhoneNumber',
		fieldLabel: 'Phone number',
		allowBlank: false,
		anchor    : '100%'		
	});	
	
	var birthDateField = new Ext.form.DateField({
		xtype: 'Datefield',
		id: 'birthDate',
		fieldLabel: 'Date of birthday',
		allowBlank:false,
		anchor: '100%'		
	});
	
	var dateCreatedField = new Ext.form.DateField({
		xtype: 'Datefield',
		id: 'dateCreated',
		fieldLabel: 'Date created',
		allowBlank:true,
		anchor: '100%'		
	});
	
	
	/*getPath()-Returns the path for this node. The path can be used to expand or select this node programmatically.
	Returns String.The path*/
	var selNodePath = selNode.getPath();
	var treePanel = Ext.getCmp('companyTreePanel');
	
	if (selNode.id =='CompanyTreeRoot') {
		var aItems = [textAreaTitle, textAreaDescription, dateCreatedField];
		var wTitle = "Add new Tur";
		
			var form = new Ext.FormPanel({
				id: 'TurAddPanelId',
				labelWidth: 100,
				frame:true,
				//title: wTitle,
				bodyStyle:'padding:5px 5px 0',
				width: 450,
				height:300,
				defaults: {width: 300},
				defaultType: 'textfield',
				items: aItems
			});		 
	}
	else if (selNode.id.match('Tur')) { 
		var aItems = [textAreaTitle, textAreaAdress, textAreaWebsite, textAreaDescription, dateCreatedField];
		var wTitle = "Add new Hotel";
		
		 var form = new Ext.FormPanel({
				id: 'HotelAddPanelId',
				labelWidth: 100,
				frame:true,
				//title: wTitle,
				bodyStyle:'padding:5px 5px 0',
				width: 450,
				height:300,
				defaults: {width: 300},
				defaultType: 'textfield',
				items: aItems
			});		 
	}	
	else if (selNode.id.match('Hotel')) { 
		var aItems = [textAreaTitle, textAreaPrice,dateCreatedField];
		var wTitle = "Add new Times";
		
		 var form = new Ext.FormPanel({
				id: 'TimesAddPanelId',
				labelWidth: 100,
				frame:true,
				//title: wTitle,
				bodyStyle:'padding:5px 5px 0',
				width: 450,
				height:300,
				defaults: {width: 300},
				defaultType: 'textfield',
				items: aItems
			});		 
	}
	else if (selNode.id.match('Times')) {
		var aItems = [textAreaTitle,textAreaCompanyName,textAreaCountPersons,textAreaTouristName,textAreaPhoneNumber,textAreaDescription,birthDateField];
		var wTitle = "Add new Request";
			
		 var form = new Ext.FormPanel({
			id: 'requestAddPanel',
			labelWidth: 100,
			frame:true,
			//title: wTitle,			
			bodyStyle:'padding:5px 5px 0',
			width: 450,
			height:300,
			defaults: {width: 300},
			defaultType: 'textfield',
			items: aItems
		});			 
	}	   	
	 	

	var window = new Ext.Window({
        title: wTitle,
       // width: 450,
       // height:300,
      //  layout: 'fit',
        //plain:true,
        //border:false,
        modal:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: form,

        buttons: [{
        	text: 'Add',        	
        	handler: function() {
        		form.getForm().submit({        		
        			url : 'manager/addElement',
        			params : {
        				node : selNode.id        			
        			},
        			waitTitle: 'please wait...',
        			waitMsg: 'wait...',
        			success: function(form, action) {
        				var result = action.result;        				
        				if (result.success === "true") {	
        					window.close();	                	
            				root = Ext.getCmp('companyTreePanel').getRootNode();
            				root.reload();
            				treePanel.expandPath(selNodePath);           
           				}else if (result.success === "false"){ 
           					//processErrors(result)  
	           				 if('errors' in result) {
		           				 var obj = result.errors[0];
			           				 var errors = '';
			           				 for (var p in obj) {
			           				 errors += obj[p] + '\n';
		           				 }
			           				 Ext.Msg.alert('ERROR', errors);
		           				 } 
		           			}        				
        			},
        			failure: function(form, action) {           			      	
        				Ext.Msg.alert('An error occured with the server.');
        			}
        		});
        	}      		
        }]
    });
    window.show();
};
